package com.kanesoft.android.gdx.actors.fight;

import com.badlogic.gdx.math.Vector2;
import com.kanesoft.android.gdx.widgets.sprites.SpriteInfo;

public class FighterLose extends FightActorStateMachine {

    private FightActorObject fightActor;

    public FighterLose(SpriteInfo stateSpriteInfo, FightActorObject actor) {
        super(stateSpriteInfo, actor);
        fightActor = actor;
    }

    @Override
    public boolean OnEnter() {
        actorSprite.setAnimationInLoop(true);
        actorSprite.setSpriteInfo(stateSpriteInfo);
        
        return true;
    }

    @Override
    public boolean OnLeave() {
        return false;
    }

    @Override
    public boolean OnUpdate() {

        if (actor.getWorldControl().isObjectOnTheGround(actor) == false) {
            actor.setActorState(fightActor.fallingState);
            return false;
        }

        fightActor.getSensorFixture().setFriction(0.2f);
        Vector2 objVelocity = fightActor.getActorBody().getLinearVelocity();

        fightActor.getActorBody().setLinearVelocity(objVelocity.x * 0.9f, objVelocity.y);
       
        return true;
    }


    @Override
    public String getStateName() {
        return "Lose";
    }

}
